<template>
	<view class="pics">
		<scroll-view class="left" scroll-y >
			<view @click=leftClickHandle(index,item.id) :class="active===index?'active':''" v-for="(item,index) in caes" :key="item.id">{{item.title}}</view>
	
		</scroll-view>
		
		<scroll-view class="right" scroll-y >	
		<view @click="yulang(item.img_url)" class="item" v-for="item in secondData" :key='item.id'>
			<image :src="item.img_url" mode=""></image>
			<text>{{item.title}}</text>
		</view>
		<text class="text" v-if='secondData.length===0'>---暂无数据---</text>
		</scroll-view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				 caes:[],
				 active:0,
				 secondData:[]
			}
		},
		methods: {
			async getPicsCate(){
			const res= await this.$myRequest({
					url:'/api/getimgcategory'
				})
				this.caes = res.data.message
				this.leftClickHandle(0,this.case[0].id)
			},
			async leftClickHandle(index,id) {
				/* console.log(index) */
				this.active=index
				/* 获取右侧的数据 */
				const res= await this.$myRequest({
					url:'/api/getimages/'+id
				})
				this.secondData= res.data.message
				
				},
				yulang(current){
					const urls = this.secondData.map(item=>{
						return item.img_url
					})
					uni.previewImage({
						current,
						urls
					})
				}
			
		},
		onLoad() {
			this.getPicsCate()
		}
	}
</script>

<style lang="scss">
	page{
		height: 100%;
	}
	.pics{
		height: 100%;
		display: flex;
		.left{
			width: 180rpx;
			height: 100%;
			border-right: 1px solid #eee;
			view{
				height: 60px;
				line-height: 60px;
				color: #333;
				text-align: center;
				font-size: 30rpx;
				border-top: 1px solid #eee;
			}
			.active{
				background-color: $shop-color;
				color: #fff;
			}
		}
		.right{
			height: 100%;
			width: 540rpx;
			margin: 12rpx auto;
			.item{
				image{
					width: 540rpx;
					height: 540rpx;
					border-radius: 5px;
					
					
				}
				text{
					font-size: 30rpx;
					line-height: 60rpx;
				}
			}
		}
		.text{
			 position: absolute;
			 margin-top: 30rpx;
			  left: 50%;
			  transform: translate(-50%, 0);//横轴和纵轴上偏移50%
		}
	}
</style>
